home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PRINTER / PROHP.ARJ / DPUBLISH.PRG < prev    next >
Text File  |  1992-06-23  |  10KB  |  285 lines

  1. /*
  2.   ┌─────────────────────────────────────────────────────────────────────────┐
  3.   │                                                                         │
  4.   │    Program : publish.prg                                                │
  5.   │                                                                         │
  6.   │    Purpose : demonstrate the use of text manipulation.                  │
  7.   │                                                                         │
  8.   │   Author  : Copyright (C) 1992, I.L.A.,Inc. All Rights reserved.        │
  9.   │                                                                         │
  10.   │   Comments: This source code may be distributed and used freely         │
  11.   │             provided that the copyright notice is not removed.          │
  12.   │                                                                         │
  13.   └─────────────────────────────────────────────────────────────────────────┘
  14.   This program can teach you a lot on how to get the most of cursor
  15.   positioning and text manipulating tricks.
  16.   Run the program first and after getting the output follow the program flow
  17.   and study it. By changing margins (lm,rm) and nTextColH you can see how
  18.   the program fit to the new measures.
  19.  
  20.   This program uses only fixed spacing font. you may modify this program
  21.   for use with proportional spacing soft font. you'll have to convert all
  22.   row col coordinates to inches and replace mlcount() and LQOUT() function.
  23.  
  24. */
  25. #include "prohp.ch"
  26.  
  27. proc main()
  28. Local lm := 5, rm := 38, nTextColH , nTopM, nVpos, nLp
  29. Local nT,nDayPos,dDate,aMo,nDayBoxLW,aCal,HPCcal:=""
  30. Local nDayT,nDayL,nDayH,nDayW,aMsg
  31. Local aData := {{100,1,"January"},;
  32.                 {400,2,"February"},;
  33.                 {372,3,"March"},;
  34.                 {50,4,"April"},;
  35.                 {210,5,"May"},;
  36.                 {400,2,"June"},;
  37.                 {372,3,"July"},;
  38.                 {50,4,"August"},;
  39.                 {210,5,"September"},;
  40.                 {372,3,"October"},;
  41.                 {50,4,"November"},;
  42.                 {350,6,"December"}}
  43. // the next line define a block to calculate the current line width in Inches.
  44. Local bPageW:= {||HP_data(D_RMI)-HP_data(D_LMI)}
  45.  
  46. // same as above but the result is in columns.
  47. Local bWidth:= {||(HP_data(D_RMI)-HP_data(D_LMI))*HP_data(D_CPI)}
  48. Local bVpos:= {|l|l/HP_data(D_LPI)}
  49. Local cText:="* The legitimate object of goverment is to do for a "+;
  50.         "community of people whatever they need to have done, but "+;
  51.         "cannot do at all in their separate and individual capacities. "+;
  52.         chr(13)+chr(10)+"- Abraham Lincoln (1809-1865)"
  53. // To see the power of ProHP try un comment the next code
  54. /*
  55. cText+=chr(13)+chr(10)+"* Voters quickly forget what a man says."+;
  56.         "-Richard M. Nixon"
  57. cText+=chr(13)+chr(10)+"* Whenever any Form of Goverment becomes destructive ..."+;
  58.         " it is the Right of the people to alter or abolish it.-"+;
  59.         "The Declaration of Independance."
  60. */
  61. HP_init()
  62. HP_send(.t.)
  63. set2print("dpublish.hpc")
  64. qqout(HP_reset())
  65. qqout(HP_pitch(10,ITALIC))     // courier 10, Italic
  66. nTopM := lqout(cText,eval(bWidth))         // print the text
  67.  
  68. // Set top margin to the number of lines used by cText +1.
  69. nTopM+=(0.5*HP_data(D_LPI))+1
  70.  
  71. // set Text Column Height to 30 lines and convert it to Inches.
  72.  HP_tmset(nTopM)
  73.  HP_rcpos(0,0)
  74.  HP_rline(0.01,eval(bPageW))     // draw line
  75. nTextColH := 40 / HP_data(D_LPI)        // make text col length to 40 lines
  76.  
  77.  HP_lmset(lm)            // set Left Margin
  78.  HP_rline(nTextColH,0.01)        // print vertical line at left margin
  79.  HP_rmset(rm)            // set Right margin
  80.  HP_rcpos(,rm)           // move cursor to right margin at the current row
  81.  HP_rline(nTextColH,0.01)        // draw vertical line at cursor pos.
  82.  HP_rcpos(0,lm)          // move to top line, left margin
  83. // fill the area between the margins with gray shade.
  84.  HP_BAR(nTextColH,HPcol2i(rm-lm),GFILLGRAY,2)
  85. nLp := lqout(cText)      // print the text
  86.  HP_rcpos(1,,.t.)        // move one line down
  87. nLp++
  88. // go to Left Margin (inch coordinates). we are not using Row Col. coordinates
  89. // because if the font pitch is changed so does the margin refference.
  90.  HP_setpos(,HP_data(D_LMI))
  91.  HP_rline(0.01,eval(bPageW))     // draw line across the text col width
  92. // will draw a graph here to the end of column
  93. HP_data(D_SHADOWTYPE,9)
  94. Graphr(nTextColH-((nLp)/HP_data(D_LPI)),eval(bPageW),aData)
  95.  
  96. // Now we create the next text column
  97. lm:=rm+2        // set new left margin to prev. Right margin + 2 columns.
  98. rm:=75          // set Right margin
  99.  HP_clrmrg()     // clear margin
  100.  HP_rcpos(0,0)   // cursor to 0,0
  101.  HP_lmset(lm)    // set LM
  102.  HP_rmset(rm)    // set RM
  103.  HP_rcpos(0,lm)  // Cursor to top row , LM
  104. // draw gray shaded area over the defined text column
  105.  HP_BAR(nTextColH,HPcol2i(rm-lm),GFILLGRAY,10)
  106. // print the text
  107. /*
  108. nLp := lqout(cText)
  109.  HP_rcpos(1,,.t.)        // one line down
  110. nLp++
  111.  HP_rcpos(,lm)           // and go to left margin
  112.  HP_rline(0.01,eval(bPageW))     // draw line
  113. nVpos := eval(bVpos,nLp)        // find Vertical position of cursor
  114. */
  115. nVpos:=0
  116.  HP_pitch(12)    // courier 12 , If your printer does not support 12 Pitch
  117.                 // you may get wider text col and the calculation of
  118.                 // LMI will not be accurate. So check printer before using.
  119. nLp:=lqout(cText)
  120.  HP_rcpos(1,,.t.)
  121. nLp++
  122.  HP_setpos(,HP_data(D_LMI))
  123.  HP_rline(0.01,eval(bPageW))
  124. nVpos += eval(bVpos,nLp)        // continue tracking Vertical Cursor pos.
  125.  HP_pitch(16)
  126.  HP_lpi(8)
  127. nLp:=lqout(cText)
  128.  HP_rcpos(1,,.t.)
  129. nLp++   //
  130.  HP_setpos(,HP_data(D_LMI))      // Go to left margin
  131.  HP_rline(0.01,eval(bPageW))     // draw separator line
  132. nLp++
  133. nVpos += eval(bVpos,nLp)        // calc current vertical pos
  134.  
  135. // now draw this month calendar
  136. aCal:=HPdrawmonth(Date(),nVpos,HP_data(D_LMI),nTextColH-nVpos,eval(bPageW))
  137. aMo:=aCal[1]
  138. HPCcal:=aCal[2]
  139. qqout(HPCcal)
  140. // mark todays date
  141. dDate:=date()
  142. // find where month is starting
  143. nT:=dow(ctod(str(month(dDate),2)+'/01/'+str(year(dDate),4)))
  144. // get the desired box pos
  145. nDayPos:=nT+day(dDate)-1
  146. nDayBoxLW:=0.05
  147. // draw a box surrounding the day box
  148.  HP_box(aMo[nDayPos,1],aMo[nDayPos,2],aMo[8,1]-aMo[1,1]-nDayBoxLW,;
  149. aMo[2,2]-aMo[1,2]-nDayBoxLW,nDayBoxLW,GFILLBLACK)
  150. // mark todays date
  151. dDate:=date()
  152. // find where month is starting
  153. nT:=dow(ctod(str(month(dDate),2)+'/01/'+str(year(dDate),4)))
  154. // get the desired box pos
  155. nDayPos:=nT+day(dDate)-1
  156.  
  157. // draw a box surrounding the day box
  158. nDayBoxLW:=0.03 // width of line to draw box
  159. nDayT:=aMo[nDayPos,1]   // top coordinate for date box
  160. nDayL:=aMo[nDayPos,2]   // left
  161. nDayH:=aMo[8,1]-aMo[1,1]-nDayBoxLW  // height of box
  162. nDayW:=aMo[2,2]-aMo[1,2]-nDayBoxLW  // Width
  163. HP_box(nDayT,nDayL,nDayH,nDayW,nDayBoxLW,GFILLBLACK) // draw the box
  164. // now we will print inside the box
  165.  HP_pitch(16) // small pitch here
  166.  HP_lpi(8)       // set LPI to 8
  167. aMsg := {"ProHP","Day"} // message array
  168. // and this is very nice
  169.  HP_aatsay(nDayT+nDayH-HProw2i(len(aMsg)+1),nDayL+nDayW/2,aMsg,,"C")
  170.  
  171.  HP_clrmrg()
  172.  
  173. // set a new top margin for this page by adding the current Top Margin Inch
  174. // to the text length.
  175. // ProHP keep track on the the margins settings and store it in HP_data()
  176. // at D_TMI we have the current Top Margin in Inch
  177.  HP_tmset((HP_data(D_TMI)+nTextColH) * HP_data(D_LPI))
  178.  HP_rcpos(0,0)
  179.  HP_rline(0.01,eval(bPageW))
  180.  HP_pitch(10)
  181.  HP_lpi(6)
  182.  HP_BAR( (mlcount(cText,eval(bWidth))+1) / HP_data(D_LPI),;
  183.         HPcol2i(eval(bWidth)),GFILLGRAY,20)
  184. lqout(cText)
  185.  
  186.  HP_rcpos(1,,.t.)
  187.  HP_setpos(,HP_data(D_LMI))
  188.  HP_rline(0.01,eval(bPageW))
  189.  
  190.  HP_reset()
  191. set2screen()
  192. return
  193.  
  194. Function lqout(cStr,nWidth)
  195. Local nTotLines, crlf := CHR(13)+chr(10), cLine, nLine
  196. nWidth := iif(nWidth == NIL,(HP_data(D_RMI)-HP_data(D_LMI))* ;
  197.         HP_data(D_CPI),nWidth)
  198. nTotLines := MLCOUNT(cStr,nWidth)
  199.  
  200. FOR nLine := 1 TO nTotLines
  201.     cLine := MEMOLINE(cStr,nWidth,nLine)
  202.     qout(cLine)
  203. NEXT
  204. return nTotLines
  205.  
  206. FUNCTION graphr(nMaxH,nMaxW,aData)
  207. LOCAL nBarSp := 1, nBarW := 1, nBarH := 1
  208. Local nLw := 0.01  // or HP_data(D_LINEWIDTH)
  209. Local nMaxVal,nBarFactor,i,nPos,nBarLength
  210. Local nOldCpi:=HP_data(D_CPI)
  211.  
  212.  HP_pitch(16,ITALIC)
  213. nBarH := nMaxH/len(aData)
  214. nBarSp := max(nBarH*0.20,2/HP_data(D_LPI))
  215. nBarH:=nBarH-nBarSp-(nBarSp/len(aData))
  216.  
  217. // find maximum value in array
  218. nPos := AMAX(aData)
  219. IF EMPTY(nPos)  // NIL or all zeros
  220.    RETURN .F.
  221. ENDIF
  222. // get the highest value in array
  223. nMaxVal := aData[nPos,1]
  224. /*
  225.   Create a factor for all array element so their bar length will be
  226.   relative to the longest one which will get the length of (Graph Width-
  227.   Shadow width).
  228. */
  229. nBarFactor := (nMaxW-(HP_data(D_SHADOWWIDTH)*2)- ;
  230.               (HP_data(D_LINEWIDTH)*2)) / nMaxVal
  231.  
  232. // draw frame of graph
  233.  HP_rbox(nMaxH,nMaxW,0.02)
  234.  
  235. FOR i:=1 to LEN(aData)
  236.      HP_setpos(nBarSp,,.T.)      // do a little space
  237.     // draw first box
  238.     nBarLength :=aData[i,1]*nBarFactor-HP_data(D_SHADOWWIDTH)
  239.      HP_rbox(nBarH,nBarLength,nLw,GFILLBLACK)
  240.      HP_savecsr()        // save csr pos
  241.      hp_setpos(nLw,,.t.) // move right to start draw after line width
  242.     // draw a bar inside the box
  243.      HP_bar(nBarH-nLw,nBarLength-nLw)
  244.      HP_restcsr()        // restore csr
  245.      HP_savecsr()        // save csr pos
  246.     // print at top of box the message for this box and its value
  247.      HP_atsay(-(0.25/HP_data(D_LPI)),1/HP_data(D_CPI),aData[I,3]+;
  248.         ' ('+ltrim(str(aData[i,1]))+')',.T.)
  249.      HP_restcsr()        // restore csr pos
  250.      HP_setpos(nBarH,,.t.)       // move down nBarH
  251. NEXT
  252.  HP_pitch(nOldCpi)
  253. RETURN ""
  254.  
  255. FUNCTION AMax( aArray )
  256. LOCAL nLen, nPos, expLast, nElement
  257.  
  258.    DO CASE
  259.  
  260.    // Invalid argument
  261.    CASE VALTYPE( aArray ) <> "A"
  262.       RETURN NIL
  263.  
  264.    // Empty argument
  265.    CASE EMPTY( aArray )
  266.       RETURN 0
  267.  
  268.    OTHERWISE
  269.       nLen := LEN( aArray )
  270.       nPos := 1
  271.       expLast := aArray[1,1]
  272.       FOR nElement := 2 TO nLen
  273.          IF aArray[nElement,1] > expLast
  274.             nPos := nElement
  275.             expLast := aArray[nElement,1]
  276.          ENDIF
  277.       NEXT
  278.  
  279.    ENDCASE
  280.  
  281.    RETURN nPos
  282.  
  283.  
  284.  
  285.